import { ObjectDirective } from 'vue';
import { throttle } from 'lodash';

export const loadmore: ObjectDirective = {
    updated(el: HTMLButtonElement, binding) {
        if (binding.value == undefined || !el) return;
        const target = document.querySelector('.rc-virtual-list-holder')!;
        const flag = true;
        let timer: number;
        if (target) {
            target.addEventListener(
                'scroll',
                throttle(() => {
                    const enable = target.scrollHeight - target.scrollTop == target.clientHeight;
                    if (enable) {
                        clearTimeout(timer);
                        timer = window.setTimeout(() => {
                            console.log('look');
                        }, 500);
                    }
                }, 100)
            );
        }
    },
};
